package demo3;

class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name=name;
        this.age=age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    @Override
    public int compareTo(Student o) {
        return this.age-o.age;
    }
}

public class Test1 {
    public static void main(String[] args) {
        Student s1=new Student("zhangshan",20);
        Student s2=new Student("lisi",20);

        if (s1.compareTo(s2) > 0) {
            System.out.println(s1.name + ">" + s2.name);
        }else if(s1.compareTo(s2) < 0) {
            System.out.println(s1.name + "<" + s2.name);
        }else {
            System.out.println(s1.name + "=" + s2.name);

        }
    }
}
